package com.teach.service.impl;

import javax.servlet.http.HttpSession;

import com.teach.Excption.CodeException;

import cn.hutool.core.util.StrUtil;
public class Const {
	public static final String CODE_NAME = "_CODE_NAME";
	public static final String LOGIN_USER_SESSION_NAME = "user";
	/***
	 * 验证码的服务器端验证 * @param session * @param code * @throws CodeException 10:验证码不能为空
	 * 11:验证码已失效 12:验 证码不匹配
	 */
	public static void codeVerify(HttpSession session, String code) throws CodeException {
		if (StrUtil.isEmpty(code)) {
			throw new CodeException(10, "验证码不能为空");
		}
		if (session.getAttribute(CODE_NAME) == null) {
			throw new CodeException(11, "验证码已失效");
		}
		if (!code.equals(session.getAttribute(CODE_NAME))) {
			throw new CodeException(12, "验证码不匹配");
		}
	}
}